<?php
class PNCustomer extends PNObject {
  function PNCustomer($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'spaservice_customer';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';

    $this->_init($init, $where);
  }
  
  function getDataFromInputJSON()
  {
      $stdClass = json_decode(file_get_contents('php://input'));
      
      foreach($stdClass AS $key=>$val){
        $obj[$key] = $val;
      }
      if ($obj) {
          $this->_objData = $obj;
          $this->getDataFromInputPostProcess();
          return $this->_objData;
      }

      return $default;
  }
  
  function insertPostProcess()
  {
    $form = FormUtil::getPassedValue('form',FALSE);
     
    $customerServiceTable = 'spaservice_customerservice';   
    $object[]  = array(
        'customer_id' => $this->_objData['id']
        );
       
    //Do the insert
    DBUtil::insertObjectArray($object, $customerServiceTable);    
    unset($object);
    $pntables = pnDBGetTables();
    $tableCustomerService = $pntables['spaservice_customerservice'];
    $lastID = DBUtil::getInsertID($tableCustomerService);
    
    $customerService_presentHistoryTable = 'spaservice_customerservice_presenthistory';
    
    foreach($form['presentHistories_id'] AS $value){
      $object[]  = array(
        'customerService_id' => $lastID,
        'presentHistory_id'=>$value
        );
    }
    
    var_dump($object); 
    //Do the insert
    var_dump(DBUtil::insertObjectArray($object, $customerService_presentHistoryTable));
    unset($object);
    exit;    
  }  
   
}